package com.xiaofeng.Hello;

public class Java10 {
    public static void main(String[] args) {

        int oldArry[] = {1, 2, 3, 4, 5};
        System.out.printf("原数组：");
        for (int i = 0; i < oldArry.length; i++) {
            System.out.printf("%d ", oldArry[i]);
        }
        System.out.printf("\n");

        //复制数组
        int new_Arry[] = copyArray(oldArry, 1, 3);
        System.out.printf("复制得到的新的数组：");
        for (int i = 0; i < new_Arry.length; i++) {
            System.out.printf("%d ", new_Arry[i]);//使用该种方式输出的时候必须按照格式化的方式进行输出
        }
        System.out.printf("\n");
        //在数组中判断一个元素是否存在
        boolean exit = isExit(oldArry, 3);
        System.out.println(exit);

    }
    //方法的定义
    public static int[] copyArray(int[] oldArry, int start, int end){
        int new_Arry[] = new int[end - start + 1];
        for (int i = start; i <= end; i++) {
            new_Arry[i - start] = oldArry[i];
        }
        return new_Arry;
    }
    //判断元素是否在数组中存在
    public static boolean isExit(int arr[],int key){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==key){
                return true;
            }
        }
        return false;
    }
}